package com.tbit.api;

import com.tbit.manager.api.VipCardApi;
import com.tbit.manager.api.dto.PackageDelayDTO;
import com.tbit.manager.api.dto.UserMemberDTO;
import com.tbit.uqbike.object.pojo.UserMember;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.VipCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 会员卡
 *
 * @author ：zhangtianyou
 * @since 2024/11/22
 */
@RestController
@Slf4j
public class VipCardApiImpl implements VipCardApi {

    @Autowired
    private VipCardService vipCardService;
    @Override
    public List<UserMemberDTO> userVipPage(Integer accountId, Integer userId, String phone, Integer pageNumber,
                                           Integer pageSize, Date startTime, Date endTime) {
        List<UserMember> userMemberList = vipCardService.userVipPage(accountId, userId, phone, pageNumber, pageSize, startTime, endTime);
        List<UserMemberDTO> userMemberDTOList = new ArrayList<>();
        for (UserMember userMember : userMemberList) {
            UserMemberDTO userMemberDTO = new UserMemberDTO();
            BeanUtils.copyProperties(userMember, userMemberDTO);
            userMemberDTOList.add(userMemberDTO);
        }
        return userMemberDTOList;
    }

    @Override
    public String modifyVipCardExpireTime(PackageDelayDTO delayDTO) {
        com.tbit.uqbike.object.pojo.dto.PackageDelayDTO packageDelayDTO = new com.tbit.uqbike.object.pojo.dto.PackageDelayDTO();
        BeanUtils.copyProperties(delayDTO,packageDelayDTO);
        packageDelayDTO.setDelayTime(delayDTO.getDelayTime().getTime());
        Result<String> stringResult = vipCardService.modifyVipCardExpireTime(packageDelayDTO);
        return stringResult.getData();
    }
}
